// miniprogram/pages/chart/we-run/we-run.js
Page({

  data: {

  },
  onLoad: function (options) {
    this.getUserRunData()
  },
  onShareAppMessage: function () {

  },
  getUserRunData() {
    wx.getWeRunData({
      success: res => {
        // 或拿 cloudID 通过云调用直接获取开放数据
        const cloudID = res.cloudID
        console.log(res)
        // 使用云函数
        wx.cloud.callFunction({
          name: 'wxPower',
          data: {
            action: 'getWeRunData',
            weRunData: wx.cloud.CloudID(cloudID)
          }
        }).then(res => {
          console.log(res)
          this.setData({
            runContent: JSON.stringify(res)
          })
          this.initRunChart()
        })
      }
    })
  },
  initRunChart() {
    let runContent = this.data.runContent
    let runData = JSON.parse(runContent)
    runData = runData.result.data.stepInfoList
    var chartComponent = this.selectComponent("#run_chart");
    chartComponent.initLineChart(runData)
  }
})